package com.si.controller.web;

import java.util.HashMap;
import java.util.List;

import com.si.util.Paging;
import com.si.util.QueryWhere;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.si.entity.BrandActivity;
import com.si.service.BrandActivityService;
import com.si.service.InfoService;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 品种推介
 * @author x1c
 *
 */
@Controller
@RequestMapping("/brandActivity")
public class BrandActivityController {

	@Autowired
	private BrandActivityService brandActivityService;
	@Autowired
	private InfoService infoService;
	
	/**
	 * 品种推介主页
	 * @return
	 */
	@RequestMapping("/ret")
	public String load(ModelMap modelMap,@RequestParam(value = "curPage", defaultValue = "0", required = false) Integer curPage,
					   @RequestParam(value = "pageSize", defaultValue = "6", required = false) Integer pageSize) {
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<BrandActivity> paging = brandActivityService.createCriteriaPaging(curPage, pageSize);
		modelMap.put("paging", paging);
		return "webPage/brandActivity/list";
	}
	
	/**
	 * 品种推介详细页面
	 * @return
	 */
	@RequestMapping(value="view/{id}")
	public String view(ModelMap modelMap,@PathVariable(value="id") Integer brandActivityId) {
		BrandActivity brandActivity=(BrandActivity)brandActivityService.getObjectById(brandActivityId);
		modelMap.put("brandActivity", brandActivity);
		return "webPage/brandActivity/view";
	}
}
